home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue69 / Clinic / IntfPropTest.pas next >
Encoding:
Pascal/Delphi Source File  |  2001-03-15  |  1.5 KB  |  77 lines

  1. unit IntfPropTest;
  2.  
  3. interface
  4.  
  5. uses
  6. {$ifdef MSWindows}
  7.   Windows, Messages, SysUtils, Classes;
  8. {$endif}
  9. {$ifdef Linux}
  10.   SysUtils, Classes;
  11. {$endif}
  12.  
  13. type
  14.   IMyInterface = interface(IInterface)
  15.   ['{329F5DD8-697B-46E2-9ABD-07BD7F439C73}']
  16.     procedure DoSomething;
  17.   end;
  18.  
  19.   TIntfImplementor = class(TComponent, IMyInterface)
  20.   protected
  21.     procedure DoSomething;
  22.   end;
  23.  
  24.   TIntfPropTest = class(TComponent)
  25.   private
  26.     FIntfProp: IMyInterface;
  27.   protected
  28.     procedure SetIntfProp(Value: IMyInterface);
  29.   public
  30.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  31.   published
  32.     property IntfProp: IMyInterface read FIntfProp write SetIntfProp;
  33.   end;
  34.  
  35. procedure Register;
  36.  
  37. implementation
  38.  
  39. uses
  40. {$ifdef MSWindows}
  41.   Dialogs;
  42. {$endif}
  43. {$ifdef Linux}
  44.   QDialogs;
  45. {$endif}
  46.  
  47. procedure Register;
  48. begin
  49.   RegisterComponents('Clinic', [TIntfPropTest, TIntfImplementor]);
  50. end;
  51.  
  52. { TIntfPropTest }
  53.  
  54. procedure TIntfPropTest.Notification(AComponent: TComponent;
  55.   Operation: TOperation);
  56. begin
  57.   inherited;
  58.   if Assigned(IntfProp) and AComponent.IsImplementorOf(IntfProp) then
  59.     IntfProp := nil;
  60. end;
  61.  
  62. procedure TIntfPropTest.SetIntfProp(Value: IMyInterface);
  63. begin
  64.   ReferenceInterface(FIntfProp, opRemove);
  65.   FIntfProp := Value;
  66.   ReferenceInterface(FIntfProp, opInsert);
  67. end;
  68.  
  69. { TIntfImplementor }
  70.  
  71. procedure TIntfImplementor.DoSomething;
  72. begin
  73.   ShowMessageFmt('Doing something in a %s object', [ClassName])
  74. end;
  75.  
  76. end.
  77.